/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.TextField
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Modality
 *  javafx.stage.Stage
 *  javafx.util.StringConverter
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SalesReceiptsUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.ChangePriceByPersionController;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.example.GetUserOutData;
import com.gys.data.salesReceipts.GetPdAndExpOutData;
import com.gys.data.salesReceipts.GetSalesReceiptsTableOutData;
import com.gys.view.salesReceipts.ChangePriceByPersionView;
import com.gys.view.salesReceipts.SpliteProView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class SpliteProController
extends BaseController
implements Initializable {
    @FXML
    private TextField proCode;
    @FXML
    private TextField needSpliteNum;
    @FXML
    private TextField price;
    @FXML
    private TextField qty;
    @FXML
    private TextField num;
    @FXML
    private TextField proUnit;
    @FXML
    private ComboBox<GetPdAndExpOutData> gssdBatchNo;
    @FXML
    private TextField afterSplitePrice;
    @FXML
    private TextField proName;
    @FXML
    private AnchorPane pane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;
    @Autowired
    private ChangePriceByPersionController changePriceByPersionController;
    public boolean changePriceByPersion = false;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.needSpliteNum.clear();
        this.needSpliteNum.requestFocus();
        this.changePriceByPersion = false;
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                SpliteProView view = SpringUtil.getBean(SpliteProView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.ENTER) {
                            SpliteProController.this.sureAction();
                        } else if (e.getCode() == KeyCode.ESCAPE) {
                            SpliteProController.this.cancelAction();
                        }
                        e.consume();
                    }
                });
            }
        }, 200L);
        GetSalesReceiptsTableOutData salesReceiptsTableOutData = (GetSalesReceiptsTableOutData)this.salesReceiptsMainController.getTableView().getSelectionModel().getSelectedItem();
        this.proCode.setText(salesReceiptsTableOutData.getProCode());
        this.proName.setText(salesReceiptsTableOutData.getProName());
        this.price.setText(salesReceiptsTableOutData.getPrcAmountD());
        this.comboxInit(this.gssdBatchNo);
        this.gssdBatchNo.setValue(new GetPdAndExpOutData());
        if (ObjectUtil.isNotEmpty(salesReceiptsTableOutData.getPdAndExpData())) {
            this.qty.setText(salesReceiptsTableOutData.getPdAndExpData().getGssbQty());
            this.num.setText(salesReceiptsTableOutData.getPdAndExpData().getProPartRate());
            this.proUnit.setText(salesReceiptsTableOutData.getPdAndExpData().getProPartUint());
            if (ObjectUtil.isNotEmpty(salesReceiptsTableOutData.getPdAndExpData())) {
                this.gssdBatchNo.setValue(salesReceiptsTableOutData.getPdAndExpData());
            }
        }
        ObservableList options = FXCollections.observableArrayList(salesReceiptsTableOutData.getPdAndExpOutDataList());
        this.gssdBatchNo.setItems(options);
        this.needSpliteNum.textProperty().addListener((ChangeListener)new ChangeListener<String>(){

            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if (ObjectUtil.isEmpty(newValue)) {
                    SpliteProController.this.needSpliteNum.clear();
                    return;
                }
                if (!CommonUtil.positiveInteger(newValue) || newValue.equals("0") || newValue.length() > 5) {
                    SpliteProController.this.needSpliteNum.setText(oldValue);
                    return;
                }
                if (Integer.valueOf(newValue) > Integer.valueOf(SpliteProController.this.num.getText())) {
                    SpliteProController.this.needSpliteNum.setText(oldValue);
                    Alert alert = SpliteProController.this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u9700\u62c6\u96f6\u9500\u552e\u6570\u91cf \u4e0d\u80fd\u5927\u4e8e \u53ef\u62c6\u96f6\u6570\u91cf");
                    alert.showAndWait();
                    return;
                }
            }
        });
        HashMap<String, Object> param = new HashMap<String, Object>();
        GetUserOutData loginUser = this.getLoginUser();
        param.put("clent", loginUser.getClient());
        param.put("prcStore", loginUser.getDepId());
        param.put("prcProduct", salesReceiptsTableOutData.getProCode());
        HttpJson httpJson = SalesReceiptsUtil.afterSplitePrice(param);
        if (httpJson.isSuccess()) {
            String result = (String)JSON.parseObject((String)httpJson.getMsg(), String.class);
            if (ObjectUtil.isNotEmpty(result)) {
                this.afterSplitePrice.setText(result);
                this.needSpliteNum.textProperty().addListener((ChangeListener)new ChangeListener<String>(){

                    public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                        if (ObjectUtil.isEmpty(newValue)) {
                            return;
                        }
                        if (!CommonUtil.positiveInteger(newValue) || newValue.equals("0") || newValue.length() > 5) {
                            SpliteProController.this.needSpliteNum.setText(oldValue);
                            return;
                        }
                    }
                });
            } else {
                Float money = Float.valueOf(Float.valueOf(this.price.getText()).floatValue() / Float.valueOf(this.num.getText()).floatValue());
                this.afterSplitePrice.setText(CommonUtil.format2(money.floatValue()));
            }
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
    }

    @FXML
    private void changeBatchNoAction() {
        if (ObjectUtil.isNotEmpty(this.gssdBatchNo.getValue())) {
            String qtyStr = ((GetPdAndExpOutData)this.gssdBatchNo.getValue()).getGssbQty();
            this.qty.setText(qtyStr);
        }
    }

    private void comboxInit(ComboBox gssdBatchNo) {
        gssdBatchNo.converterProperty().set(new StringConverter<GetPdAndExpOutData>(){

            public String toString(GetPdAndExpOutData object) {
                return object.getGssbBatchNo();
            }

            public GetPdAndExpOutData fromString(String string) {
                return null;
            }
        });
    }

    @FXML
    private void changePrice() {
        this.changePriceByPersionController.init();
        CommonUtil.showView(ChangePriceByPersionView.class, Modality.APPLICATION_MODAL);
    }

    @FXML
    private void sureAction() {
        if (ObjectUtil.isEmpty(this.needSpliteNum.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u9700\u62c6\u96f6\u9500\u552e\u6570\u91cf\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        if (Float.valueOf(this.needSpliteNum.getText()).floatValue() > Float.valueOf(this.num.getText()).floatValue()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u9700\u62c6\u96f6\u9500\u552e\u6570\u91cf \u4e0d\u80fd\u5927\u4e8e \u53ef\u62c6\u96f6\u6570\u91cf");
            alert.showAndWait();
            return;
        }
        if (ObjectUtil.isEmpty(((GetPdAndExpOutData)this.gssdBatchNo.getValue()).getGssbBatch())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u9009\u62e9\u6279\u53f7");
            alert.showAndWait();
            return;
        }
        GetSalesReceiptsTableOutData salesReceiptsTableOutData = (GetSalesReceiptsTableOutData)this.salesReceiptsMainController.getTableView().getSelectionModel().getSelectedItem();
        salesReceiptsTableOutData.setPdAndExpData((GetPdAndExpOutData)this.gssdBatchNo.getValue());
        float splitePrice = 1.0f / Float.valueOf(this.num.getText()).floatValue() * Float.valueOf(this.needSpliteNum.getText()).floatValue();
        salesReceiptsTableOutData.setNum(CommonUtil.format2(splitePrice));
        salesReceiptsTableOutData.setPrcAmount(this.afterSplitePrice.getText());
        salesReceiptsTableOutData.setPrice(this.afterSplitePrice.getText());
        Float mo = Float.valueOf(Float.valueOf(this.afterSplitePrice.getText()).floatValue() * Float.valueOf(this.needSpliteNum.getText()).floatValue());
        salesReceiptsTableOutData.setTotal(CommonUtil.format2(mo.floatValue()));
        salesReceiptsTableOutData.setStatus("\u62c6\u96f6");
        this.salesReceiptsMainController.getTableView().refresh();
        String index = salesReceiptsTableOutData.getIndex();
        this.salesReceiptsMainController.getTableView().getSelectionModel().clearSelection();
        this.salesReceiptsMainController.getTableView().getSelectionModel().select(Integer.valueOf(index) - 1);
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }

    public TextField getProCode() {
        return this.proCode;
    }

    public TextField getNeedSpliteNum() {
        return this.needSpliteNum;
    }

    public TextField getPrice() {
        return this.price;
    }

    public TextField getQty() {
        return this.qty;
    }

    public TextField getNum() {
        return this.num;
    }

    public TextField getProUnit() {
        return this.proUnit;
    }

    public ComboBox<GetPdAndExpOutData> getGssdBatchNo() {
        return this.gssdBatchNo;
    }

    public TextField getAfterSplitePrice() {
        return this.afterSplitePrice;
    }

    public TextField getProName() {
        return this.proName;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public SalesReceiptsMainController getSalesReceiptsMainController() {
        return this.salesReceiptsMainController;
    }

    public ChangePriceByPersionController getChangePriceByPersionController() {
        return this.changePriceByPersionController;
    }

    public boolean isChangePriceByPersion() {
        return this.changePriceByPersion;
    }

    public void setProCode(TextField proCode) {
        this.proCode = proCode;
    }

    public void setNeedSpliteNum(TextField needSpliteNum) {
        this.needSpliteNum = needSpliteNum;
    }

    public void setPrice(TextField price) {
        this.price = price;
    }

    public void setQty(TextField qty) {
        this.qty = qty;
    }

    public void setNum(TextField num) {
        this.num = num;
    }

    public void setProUnit(TextField proUnit) {
        this.proUnit = proUnit;
    }

    public void setGssdBatchNo(ComboBox<GetPdAndExpOutData> gssdBatchNo) {
        this.gssdBatchNo = gssdBatchNo;
    }

    public void setAfterSplitePrice(TextField afterSplitePrice) {
        this.afterSplitePrice = afterSplitePrice;
    }

    public void setProName(TextField proName) {
        this.proName = proName;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setSalesReceiptsMainController(SalesReceiptsMainController salesReceiptsMainController) {
        this.salesReceiptsMainController = salesReceiptsMainController;
    }

    public void setChangePriceByPersionController(ChangePriceByPersionController changePriceByPersionController) {
        this.changePriceByPersionController = changePriceByPersionController;
    }

    public void setChangePriceByPersion(boolean changePriceByPersion) {
        this.changePriceByPersion = changePriceByPersion;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof SpliteProController)) {
            return false;
        }
        SpliteProController other = (SpliteProController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        TextField this$proCode = this.getProCode();
        TextField other$proCode = other.getProCode();
        if (this$proCode == null ? other$proCode != null : !this$proCode.equals(other$proCode)) {
            return false;
        }
        TextField this$needSpliteNum = this.getNeedSpliteNum();
        TextField other$needSpliteNum = other.getNeedSpliteNum();
        if (this$needSpliteNum == null ? other$needSpliteNum != null : !this$needSpliteNum.equals(other$needSpliteNum)) {
            return false;
        }
        TextField this$price = this.getPrice();
        TextField other$price = other.getPrice();
        if (this$price == null ? other$price != null : !this$price.equals(other$price)) {
            return false;
        }
        TextField this$qty = this.getQty();
        TextField other$qty = other.getQty();
        if (this$qty == null ? other$qty != null : !this$qty.equals(other$qty)) {
            return false;
        }
        TextField this$num = this.getNum();
        TextField other$num = other.getNum();
        if (this$num == null ? other$num != null : !this$num.equals(other$num)) {
            return false;
        }
        TextField this$proUnit = this.getProUnit();
        TextField other$proUnit = other.getProUnit();
        if (this$proUnit == null ? other$proUnit != null : !this$proUnit.equals(other$proUnit)) {
            return false;
        }
        ComboBox<GetPdAndExpOutData> this$gssdBatchNo = this.getGssdBatchNo();
        ComboBox<GetPdAndExpOutData> other$gssdBatchNo = other.getGssdBatchNo();
        if (this$gssdBatchNo == null ? other$gssdBatchNo != null : !this$gssdBatchNo.equals(other$gssdBatchNo)) {
            return false;
        }
        TextField this$afterSplitePrice = this.getAfterSplitePrice();
        TextField other$afterSplitePrice = other.getAfterSplitePrice();
        if (this$afterSplitePrice == null ? other$afterSplitePrice != null : !this$afterSplitePrice.equals(other$afterSplitePrice)) {
            return false;
        }
        TextField this$proName = this.getProName();
        TextField other$proName = other.getProName();
        if (this$proName == null ? other$proName != null : !this$proName.equals(other$proName)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        SalesReceiptsMainController this$salesReceiptsMainController = this.getSalesReceiptsMainController();
        SalesReceiptsMainController other$salesReceiptsMainController = other.getSalesReceiptsMainController();
        if (this$salesReceiptsMainController == null ? other$salesReceiptsMainController != null : !(this$salesReceiptsMainController).equals(other$salesReceiptsMainController)) {
            return false;
        }
        ChangePriceByPersionController this$changePriceByPersionController = this.getChangePriceByPersionController();
        ChangePriceByPersionController other$changePriceByPersionController = other.getChangePriceByPersionController();
        if (this$changePriceByPersionController == null ? other$changePriceByPersionController != null : !this$changePriceByPersionController.equals(other$changePriceByPersionController)) {
            return false;
        }
        return this.isChangePriceByPersion() == other.isChangePriceByPersion();
    }

    protected boolean canEqual(Object other) {
        return other instanceof SpliteProController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        TextField $proCode = this.getProCode();
        result = result * 59 + ($proCode == null ? 43 : $proCode.hashCode());
        TextField $needSpliteNum = this.getNeedSpliteNum();
        result = result * 59 + ($needSpliteNum == null ? 43 : $needSpliteNum.hashCode());
        TextField $price = this.getPrice();
        result = result * 59 + ($price == null ? 43 : $price.hashCode());
        TextField $qty = this.getQty();
        result = result * 59 + ($qty == null ? 43 : $qty.hashCode());
        TextField $num = this.getNum();
        result = result * 59 + ($num == null ? 43 : $num.hashCode());
        TextField $proUnit = this.getProUnit();
        result = result * 59 + ($proUnit == null ? 43 : $proUnit.hashCode());
        ComboBox<GetPdAndExpOutData> $gssdBatchNo = this.getGssdBatchNo();
        result = result * 59 + ($gssdBatchNo == null ? 43 : $gssdBatchNo.hashCode());
        TextField $afterSplitePrice = this.getAfterSplitePrice();
        result = result * 59 + ($afterSplitePrice == null ? 43 : $afterSplitePrice.hashCode());
        TextField $proName = this.getProName();
        result = result * 59 + ($proName == null ? 43 : $proName.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        SalesReceiptsMainController $salesReceiptsMainController = this.getSalesReceiptsMainController();
        result = result * 59 + ($salesReceiptsMainController == null ? 43 : ($salesReceiptsMainController).hashCode());
        ChangePriceByPersionController $changePriceByPersionController = this.getChangePriceByPersionController();
        result = result * 59 + ($changePriceByPersionController == null ? 43 : $changePriceByPersionController.hashCode());
        result = result * 59 + (this.isChangePriceByPersion() ? 79 : 97);
        return result;
    }

    public String toString() {
        return "SpliteProController(proCode=" + this.getProCode() + ", needSpliteNum=" + this.getNeedSpliteNum() + ", price=" + this.getPrice() + ", qty=" + this.getQty() + ", num=" + this.getNum() + ", proUnit=" + this.getProUnit() + ", gssdBatchNo=" + this.getGssdBatchNo() + ", afterSplitePrice=" + this.getAfterSplitePrice() + ", proName=" + this.getProName() + ", pane=" + this.getPane() + ", salesReceiptsMainController=" + this.getSalesReceiptsMainController() + ", changePriceByPersionController=" + this.getChangePriceByPersionController() + ", changePriceByPersion=" + this.isChangePriceByPersion() + ")";
    }
}

